﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NWBA_Public.WebForms
{
    public partial class Billing : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((string)(Session["userName"]) == null)
            {
                //if not logged in direct him to login.aspx
                Response.Redirect("Login.aspx", true);
            }
            Customer cust = Session["Customer"] as Customer;
        }

        protected void btnTrigger_Click(object sender, EventArgs e)
        {
            if (cldDatetime.SelectedDate == null)
            {
                lblMsg.Text = "No date is selected.";
            }
            else
            {
                List<Account> allAccounts = AccountRepostiory.SelectAll();
                lblMsg.Text = "";
                foreach (Account acct in allAccounts)
                {
                    lblMsg.Text += BillRepository.TriggerBills(acct, cldDatetime.SelectedDate);
                }
                if (lblMsg.Text == "")
                {
                    lblMsg.Text = "All bills have been paid successfully.";
                }
            }
        }
    }
}